package com.jfinal.club._admin.Handwriting;

import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONObject;

import com.baidu.aip.ocr.AipOcr;

public class Handwriting {
    //设置APPID/AK/SK
    public static final String APP_ID = "20158265";
    public static final String API_KEY = "OnC42gRTC8bMheWXyXKSHpOt";
    public static final String SECRET_KEY = "vrki62OyvkzmaDr703lMM8vjqOU4uKuc";

    public  String  Handwriting(String path) {
        // 初始化一个AipOcr
        AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
   
        JSONObject jsonObject = client.basicGeneral(path, new HashMap<String, String>());
        System.out.println(jsonObject.toString());
        JSONArray jsonArray = jsonObject.getJSONArray("words_result");
        String result="";
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject2 = jsonArray.getJSONObject(i);
            result=result+jsonObject2.getString("words");
        }
		return result;
    }
}